# Maintainer: Martell Malone <martellmalone@gmail.com>

pkgname="crosstool-ng"
pkgver=1.23.0
pkgrel=2
pkgdesc="A cross-platform open-source toolchain system"
arch=('i686' 'x86_64')
url="http://www.crosstool-ng.org/"
license=("MIT")
makedepends=("autoconf" "automake-wrapper" "binutils" "bison"
             "flex" "gettext-devel" "git" "gcc" "gperf"
             "patch" "libtool" "make" "ncurses-devel"
             "tar" "texinfo" "wget" "xz")
depends=("ncurses" "libintl")
options=('staticlibs' 'strip')
source=("http://crosstool-ng.org/download/crosstool-ng/${pkgname}-${pkgver}.tar.xz"
        "0001-Modify-config-to-support-correct-Mingw64-Triplet-Nam.patch"
        "0002-use-wide-versions-of-libs-for-nconf.patch"
        "0003-modify-kconfig-make-lintl.patch"
        "0005-GNU-stats-test.patch")
sha256sums=('68a43ea98ccf9cb345cb6eec494a497b224fee24c882e8c14c6713afbbe79196'
            'a64a1caf173f9e894e7762cc0aecda0224007f6db292f2594453c4be326307fe'
            '2e9217ebfb9460f81cab5ed01d656736a9f88dda5796a57417eb94e783ffdfbb'
            '828a0b995520a5017346f5662abe0c69356e0d4bc88401b5a4f9e7e289a7aadb'
            'cf1534068b550d7905fceaa95ee7ebcdd214881a0629c23a4c752837611884eb')
noextract=(${pkgname}-${pkgver}.tar.xz)

prepare() {
  [[ -d ${srcdir}/${pkgname}-${pkgver} ]] && rm -rf ${srcdir}/${pkgname}-${pkgver}
  tar -xJf ${srcdir}/${pkgname}-${pkgver}.tar.xz -C ${srcdir} || true
  
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-Modify-config-to-support-correct-Mingw64-Triplet-Nam.patch"
  patch -p1 -i "${srcdir}/0002-use-wide-versions-of-libs-for-nconf.patch"
  patch -p1 -i "${srcdir}/0003-modify-kconfig-make-lintl.patch"
  patch -p1 -i "${srcdir}/0005-GNU-stats-test.patch"
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  autoreconf -fiv
  ./configure \
    --build=${CHOST} \
    --prefix=/usr

  make
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make DESTDIR=${pkgdir} install
}
